# -*- coding: utf-8 -*-
import scrapy
import json
from ..items import JijinItem


class ListSpider(scrapy.Spider):
    name = 'list'
    # allowed_domains = ['xxx']
    start_urls = ['http://www.szse.cn/api/report/ShowReport/data?SHOWTYPE=JSON&CATALOGID=1105&TABKEY=tab1&PAGENO=1']
    for page in range(2, 27):
        url = 'http://www.szse.cn/api/report/ShowReport/data?SHOWTYPE=JSON&CATALOGID=1105&TABKEY=tab1&PAGENO=' + str(
            page)
        start_urls.append(url)

    def parse(self, response):
        dd = json.loads(response.text[1:-1])
        for data in dd['data']:
            sys_key = data['sys_key'][68:-8]
            jjjcurl = data['jjjcurl'][104:-8]
            jjlb = data['jjlb']
            tzlb = data['tzlb']
            ssrq = data['ssrq']
            dqgm = data['dqgm']
            glrmc = data['glrmc']
            cxjqhq = 'http://www.szse.cn/api/report' + data['cxjqhq'][48:-8]
            print(glrmc)
            item = JijinItem()
            item['sys_key'] = sys_key
            item['jjjcurl'] = jjjcurl
            item['jjlb'] = jjlb
            item['tzlb'] = tzlb
            item['ssrq'] = ssrq
            item['dqgm'] = dqgm
            item['glrmc'] = glrmc
            item['cxjqhq'] = cxjqhq
            yield item
